package leetcode.biweekly.week77;

import java.util.LinkedList;
import java.util.Queue;

import leetcode.IDebug;

public class Solution3 implements IDebug {

	public int countUnguarded(int m, int n, int[][] guards, int[][] walls) {
		int[][] hash = new int[m][n];
		for (int i = 0; i < walls.length; i++) {
			int[] wall = walls[i];
			int x = wall[0], y = wall[1];
			hash[x][y] = -1;
		}
		for (int i = 0; i < guards.length; i++) {
			int[] guard = guards[i];
			int x = guard[0], y = guard[1];
			hash[x][y] = 1;
		}
		for (int i = 0; i < m; i++) {
			Integer paint = null;
			for (int j = 0; j < n; j++) {
				int cur = hash[i][j];
				if (cur == 1) {
					paint = 1;
				} else if (cur == -1) {
					paint = null;
				} else {
					if (paint != null) {
						hash[i][j] = 2;
					}
				}
			}
		}
		for (int i = 0; i < m; i++) {
			Integer paint = null;
			for (int j = n - 1; j >= 0; j--) {
				int cur = hash[i][j];
				if (cur == 1) {
					paint = 1;
				} else if (cur == -1) {
					paint = null;
				} else {
					if (paint != null) {
						hash[i][j] = 2;
					}
				}
			}
		}

		for (int j = 0; j < n; j++) {
			Integer paint = null;
			for (int i = 0; i < m; i++) {
				int cur = hash[i][j];
				if (cur == 1) {
					paint = 1;
				} else if (cur == -1) {
					paint = null;
				} else {
					if (paint != null) {
						hash[i][j] = 2;
					}
				}
			}
		}

		for (int j = 0; j < n; j++) {
			Integer paint = null;
			for (int i = m - 1; i >= 0; i--) {
				int cur = hash[i][j];
				if (cur == 1) {
					paint = 1;
				} else if (cur == -1) {
					paint = null;
				} else {
					if (paint != null) {
						hash[i][j] = 2;
					}
				}
			}
		}
		int ans = 0;
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				int cur = hash[i][j];
				if (cur == 0) {
					ans++;
				}
			}
		}
		return ans;
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution3 so = new Solution3();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
